#include "stack.h"
#include <stdlib.h>
#include <string.h>

stack* create(int len)
{
	stack* q;
	q = (stack*)malloc(sizeof(stack));
	if(q == NULL)
	{
		printf("栈空间");
		return NULL;
	}
	if((q->data = (data_t* )malloc(len * sizeof(data_t))) == NULL)
	{
		printf("data_t failed\n");
		free(q);
		return NULL;
	}

	//初始化
	memset(q->data, 0, (len*sizeof(data_t)));
	q->maxlen = len;
	int pot = -1;
	return q;


}


//入栈
int sqpush(stack * q, data_t value)
{
	if(q == NULL)
	{
		printf("q为空");
		return -1;
	}
	return 0;

	//判断是否满了
	if(q->pot == q->maxlen-1)
	{
		printf("栈满了");
		return 0;
	}
	//入栈
	q->pot++;
	q->data[q->pot] = value;
	return 0;
}

//是否为空
int empty(stack *q)
{
	return q->pot == -1? 0 : 1; 
}


//是否为满
int full(stack *q)
{
	return  q->pot == q->maxlen - 1 ? 0 : 1;
}


//出栈 
data_t pop(stack *q)
{
	int i;
	if(q == NULL)
	{
		return -1;
	}
	if((i=empty(q)) == 0)
	{
		return 0;
	}
	//特点先进后出
	q->pot--;
	return (q->data[q->pot+1]);
	
}

/*
//现在有多少元素
data_t top(stack *q)
{

	return NULL;
}


//清空
stack* clear(stack *q)
{
	meset(q, 0, (len *(sizeof(data))));
	q->top == -1;
:	return q;
}

//释放内存
stack* sqfree(stack *q)
{
	return NULL;
}
*/



